<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //多个then方法用来处理多个数据的逻辑,一旦有一个出错则会进入catch中执行
        new Promise((resolve, reject) => {
            console.log("开始请求A数据......")
            try {
                setTimeout(() => {
                    console.log("A数据请求成功");
                    //模拟请求回来的数据
                    const username = {
                        user: "laoliu"
                    }
                    resolve(username)
                }, 1500)
            } catch (e) {
                reject(e.message)
            }
        })

            .then(value => {
                return new Promise((resolve, reject) => {
                    console.log("开始请求B数据......")
                    try {
                        setTimeout(() => {
                            console.log("B数据请求成功");
                            //模拟请求回来的数据
                            const age = {
                                age: 18
                            }
                            resolve({
                                ...value,
                                ...age
                            })
                            // resolve(Object.assign({}, value, age))
                        }, 1500)
                    } catch (e) {
                        reject(e.message)
                    }
                })
            })

            .then(value => {
                return new Promise((resolve, reject) => {
                    console.log("开始请求C数据......")
                    try {
                        setTimeout(() => {
                            console.log("C数据请求成功");
                            //模拟请求回来的数据
                            const sex = {
                                sex: "男"
                            }
                            resolve({
                                ...value,
                                ...sex
                            })
                        }, 1500)
                    } catch (e) {
                        reject(e.message)
                    }
                })
            })

            .then(value => {
                //处理value
                console.log(value);
            })

            .catch(reason => {
                console.log("这里是异常处理");
            })
    </script>
</body>

</html>